package com.chunuo.eduservice.controller;


import com.chunuo.commonutils.R;
import com.chunuo.eduservice.entity.EduChapter;
import com.chunuo.eduservice.entity.vo.EduChapterVo;
import com.chunuo.eduservice.service.EduChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-04
 */
@RestController
@RequestMapping("/eduservice/edu-chapter")
//@CrossOrigin
public class EduChapterController {

    @Autowired
    private EduChapterService eduChapterService;

    @GetMapping("/findDescription/{id}")
    public R findAll(@PathVariable("id")String id){
        List<EduChapterVo> eduChapterList = eduChapterService.findDescription(id);
        return R.ok().data("data",eduChapterList);
    }

    @PostMapping("/save")
    public R save(@RequestBody EduChapter eduChapter){
        eduChapterService.save(eduChapter);
        return R.ok();
    }

    @PutMapping("/edit")
    public R update(@RequestBody EduChapter eduChapter){
        eduChapterService.updateById(eduChapter);
        return R.ok();
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable("id")String id){
        EduChapter info = eduChapterService.getById(id);
        return R.ok().data("info",info);
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id")String id){
        eduChapterService.removeById(id);
        return R.ok();
    }

}

